package org.micode.demo.db.domain.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.micode.common.validater.InsertGroup;
import org.micode.common.validater.UpdateGroup;
import org.micode.common.validater.EnumValidation;
import org.micode.common.exception.VerifyFailException;
import org.micode.common.utils.StringExtUtils;
import org.micode.common.domain.base.entity.BaseUpdEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 系统日志实体类
 *
 * @author: wutianbin
 * @version: v1.0.27
 * @CreateDate: 2021-11-10
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class LogSysDO extends BaseUpdEntity<Long> {

    /** 日志ID，Long */
    @NotNull(message = "日志ID,不能为空", groups = UpdateGroup.class)
    @PositiveOrZero(message = "日志ID,不能为负数", groups = {InsertGroup.class, UpdateGroup.class})
    private Long logId;

    /** 用户ID，Long */
    @PositiveOrZero(message = "用户ID,不能为负数", groups = {InsertGroup.class, UpdateGroup.class})
    private Long userId;

    /** 用户类型, 枚举类型: UserTypeEnum，Integer */
    private Integer userType;

    /** 记录日志时间，LocalDateTime */
    private LocalDateTime logTime;

    /** 操作模式, NORMAL,UPDATE,INSERT,DELETE，String */
    @Size(max = 10,message = "操作模式, NORMAL,UPDATE,INSERT,DELETE,最大长度10个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String operationMode;

    /** 用户操作，String */
    @Size(max = 64,message = "用户操作,最大长度64个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String operation;

    /** 请求方法，String */
    @Size(max = 256,message = "请求方法,最大长度256个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String method;

    /** 请求参数，String */
    @Size(max = 65535,message = "请求参数,最大长度65535个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String params;

    /** 执行耗时(单位：毫秒)，Long */
    @PositiveOrZero(message = "执行耗时(单位：毫秒),不能为负数", groups = {InsertGroup.class, UpdateGroup.class})
    private Long consumeMs;

    /** 发起源IP地址，String */
    @Size(max = 64,message = "发起源IP地址,最大长度64个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String originateIp;

    /** 发起源程序模块，String */
    @Size(max = 64,message = "发起源程序模块,最大长度64个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String originateModule;

    /** 发起源程序，String */
    @Size(max = 64,message = "发起源程序,最大长度64个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String originateApp;

    /** 收到的信息，String */
    @Size(max = 65535,message = "收到的信息,最大长度65535个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String recvMsg;

    @JsonIgnore
    @Override
    public Long getKeyValue() {
        return logId;
    }

    @Override
    public void checkBeforeInsert() {
    }

    @Override
    public String toString() {
        return "logId=" + logId +
                ", userId=" + userId +
                ", userType=" + userType +
                ", logTime=" + logTime +
                ", operationMode='" + operationMode + "'" +
                ", operation='" + operation + "'" +
                ", method='" + method + "'" +
                ", params='" + params + "'" +
                ", consumeMs=" + consumeMs +
                ", originateIp='" + originateIp + "'" +
                ", originateModule='" + originateModule + "'" +
                ", originateApp='" + originateApp + "'" +
                ", recvMsg='" + recvMsg + "'" +
                ", " + super.toString();
    }

}
